/**
 * Created by duwei on 2019/3/19.
 */
var ZiPai_QuickStartWindow = Window.extend({
    _ccsFileName: zipai.res.ZiPai_QuickStartWindow_json,
    initWindow: function (data) {
        var self = this;
        self.leftTime = data['Time'];
        var changeTimeFunc = function () {
            self._nodeList['root.time'].setString(self.leftTime);
            self.leftTime--;
            if (self.leftTime < 0) {
                this.unscheduleAllCallbacks();
            }
        };
        self.schedule(changeTimeFunc, 1);
        self._nodeList['root.time'].setString(self.leftTime);
        var PlayerInfo = gameData.getPlayerInfoByUid(data['ByWho']);
        self._nodeList['root.lb_name'].setString(PlayerInfo['NickName']);
        self._nodeList['root.lb_Text'].setString('邀请你开启' + data['Users'].length + '人玩法，是否同意:');
    },
    /**
     * 点击事件
     * @private
     */
    _initClickListeners: function () {
        this._super();
        this._clickListeners = {
            'root.btn_dengdeng': '_clickDengDeng',
            'root.btn_kaiju': '_clickKaiJu'
        };
    },
    _clickDengDeng: function () {
        network.sendPhz(5000, 'QuickStart/2');
        this.unscheduleAllCallbacks();
        this.setVisible(false);
    },
    _clickKaiJu: function () {
        network.sendPhz(5000, 'QuickStart/1');
        this.unscheduleAllCallbacks();
        this.setVisible(false);
    },
    refreshData: function (data) {
        var self = this;
        self.leftTime = data['Time'];
        for (var i = 0; i < data['Users'].length; i++) {
            var info = data['Users'][i];
            var PlayerInfo = gameData.getPlayerInfoByUid(info['UserID']);
            self._nodeList['root.lb_name_' + i].setString(PlayerInfo['NickName']);
            self._nodeList['root.lb_Text_' + i].setString(info['IsSet'] == 1 ? "同意" : '选择选择');
            self._nodeList['root.lb_Text_' + i].setColor(info['IsSet'] == 1 ? cc.color('41c947') : cc.color('ff8400'))
            self._nodeList['root.lb_name_' + i].setVisible(true);
            self._nodeList['root.lb_Text_' + i].setVisible(true);
        }
        for (; i < 3; i++) {
            self._nodeList['root.lb_name_' + i].setVisible(false);
            self._nodeList['root.lb_Text_' + i].setVisible(false);
        }
    },
});